package com.haochang.chunkvod.controller.adapter.cash;

import java.util.List;

import com.haochang.base.OnBaseClickListener;
import com.haochang.chunkvod.R;
import com.haochang.chunkvod.app.utils.SaleUtils;
import com.haochang.chunkvod.controller.activity.cash.PayForAnotherActivity;
import com.haochang.chunkvod.controller.adapter.base.BaseAdapterHelper;
import com.haochang.chunkvod.controller.adapter.base.QuickAdapter;
import com.haochang.chunkvod.model.cash.CashInfo;

import android.content.Context;
import android.view.View;
import android.widget.CheckBox;

/**
 * 代付列表适配器
 */
public class PayForAnotherAdapter extends QuickAdapter<CashInfo>
{
	private Context mContext;
	private PayForAnotherActivity.PayEnum payEnum;

	public PayForAnotherAdapter(Context context, int layoutResId, List data)
	{
		super(context, layoutResId, data);
		mContext = context;
	}

	public void setPayEnum(PayForAnotherActivity.PayEnum payEnum)
	{
		this.payEnum = payEnum;
	}

	@Override
	protected void convert(BaseAdapterHelper helper, CashInfo item)
	{
		helper.setText(R.id.tv_time, item.getOrderTime());
		helper.setText(R.id.tv_serialNumber, String.format("流水号：%s", item.getSerialNumber()));
		helper.setText(R.id.tv_price, SaleUtils.getSaleString(item.getTotalPrice()));
		helper.setText(R.id.tv_roomNum, item.getRoomNum());
		if (payEnum == PayForAnotherActivity.PayEnum.PRE_PAY)
			helper.getView(R.id.tv_type).setVisibility(View.VISIBLE);
		helper.setExpandText(R.id.expandTextView, item.getRemark());
		helper.setChecked(R.id.checkBox, item.isChecked());
		helper.getView(R.id.checkBox).setTag(item);
		helper.getView(R.id.checkBox).setOnClickListener(onBaseClickListener);

	}

	private OnBaseClickListener onBaseClickListener = new OnBaseClickListener()
	{
		@Override
		public void onBaseClick(View v)
		{
			switch (v.getId())
			{
			case R.id.checkBox:
				CashInfo cashInfo = (CashInfo) v.getTag();
				if (((CheckBox) v).isChecked())
				{
					cashInfo.setChecked(true);
				} else
				{
					cashInfo.setChecked(false);
				}
				notifyDataSetChanged();
				break;
			default:
				break;
			}
		}
	};
}
